<template>
  <section class="list" ref="wrapper">
    <div>
      <div class="area">
        <div class="title">当前城市</div>
        <div class="button-list">
          <div class="button-wrapper">
            <div class="button">成都</div>
          </div>
        </div>
      </div>
      <div class="area">
        <div class="title">热门城市</div>
        <div class="button-list">
          <div class="button-wrapper" v-for="item in cityList.hotCities" :key="item.id">
            <div class="button">{{item.name}}</div>
          </div>
        </div>
      </div>
      <div class="area" :ref="key" v-for="(item, key, index) in cityList.cities" :key="index">
        <div class="title">{{key}}</div>
        <div class="item-list">
          <div class="item" v-for="items of item" :key="items.id">{{items.name}}</div>
        </div>
      </div>
    </div>
  </section>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  name: 'CityList',
  props: {
    cityList: Object
  },
  // computed: {
  //   hotCities () {
  //     return cityList.hotCities
  //   },
  //   cities () {
  //     return cityList.cities
  //   }
  // },
  mounted () {
    this.scroll = new BScroll(this.$refs.wrapper)
  },
  created () {
    this.$bus.$on('letterClick', params => {
      if (params) {
        this.scroll.scrollToElement(this.$refs[params][0])
      }
    })
  }
}
</script>

<style lang="less" scoped>
  .list {
    position: absolute;
    top: 1.58rem;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    .area {
      .title {
        line-height: .54rem;
        background: #eee;
        padding-left: .2rem;
        color: #666;
        font-size: .26rem;
        border-bottom: 1px solid #ccc;
        // border-top: 1px solid #ccc;
      }
      .button-list {
        overflow: hidden;
        padding: .1rem .6rem .1rem .1rem;
        .button-wrapper {
          width: 33.33%;
          float: left;
          .button {
            padding: .1rem 0;
            text-align: center;
            margin: .1rem .1rem;
            border: .02rem solid #ccc;
            border-radius: .06rem;
          }
        }
      }
      .item-list {
        .item {
          line-height: .76rem;
          padding-left: .2rem;
          border-bottom: 1px solid #ccc;
        }
        // .item:last-child {
        //   border: 0;
        // }
      }
    }
  }
</style>
